package com.good.child.widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;

/**
 * Create on: 2024/9/28
 * by Mr.Zhu
 * Description: TODO
 */
public class MyViewPager extends ViewPager {
    public MyViewPager(@NonNull Context context) {
        super(context);
    }

    public MyViewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    private boolean scrollable = true;//默认可滑动


    public void setScrollable(boolean scrollable) {
        this.scrollable = scrollable;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        try {
            if (scrollable) {
                return super.onInterceptTouchEvent(ev);
            } else {
                return false;
            }
        } catch (Exception e) {

        }
        return scrollable;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        try {
            if (scrollable) {
                return super.onTouchEvent(ev);
            } else {
                return false;
            }
        } catch (Exception e) {

        }
        return super.onTouchEvent(ev);
    }

    @Override
    public void scrollTo(int x, int y) {
        super.scrollTo(x, y);
    }
}
